<template>
	<view class="newworkOrder_container">
		<view class="" style="height: 160rpx;">
		<view class="mail_List fixed z_ninetynine">
			<view class="mail" style="font-weight: 700;">
				<view class="order">工单信息</view>
				<!-- <view class="order" v-if="current==2">建立工单</view> -->
				<view class="order" v-if="current==2">转交工单</view>
			</view>
		</view>
		<view class="icon fixed z_ninetynine">
			<u-icon name="arrow-left" color="#fefefe" size="40" @click="navigateBack"></u-icon>
		</view>
			
		</view>
		<!-- 报事人信息 -->
		<view class="data_Statistics" style="padding: 44rpx 24rpx 0 ;">
			<text style="font-weight: 700; font-size: 30rpx; color: #c4c4c4;">丨</text><text
				style="font-weight: 700; font-size: 30rpx;">报事人信息</text>
		</view>
		<view class="card" style="padding: 0 42rpx;">
			<u-form :model="form" ref="uForm">
				<u-form-item label="报事人:">
					<u-input v-model="form.Reporter"
						placeholder-style="color: #000; text-align: right; font-weight: 600;" :placeholder="particulars.reportPerson"
						:clearable="false" :disabled="true" />
				</u-form-item>
				<u-form-item label="联系方式:">
					<view class="" style="display: flex;justify-content: flex-end;">
						<u-input v-model="form.address"
							placeholder-style="color: #000; text-align: right; font-weight: 600;"
							:placeholder="particulars.phoneNumber" :clearable="false" :disabled="true" />
						<u-rate :count="count" :min-count="1" v-model="value" @change="change"></u-rate>
					</view>
				</u-form-item>
			</u-form>
		</view>
		<!-- 报事详情 -->
		<view class="data_Statistics" style="padding: 28rpx 24rpx 0 ;">
			<text style="font-weight: 700; font-size: 30rpx; color: #c4c4c4;">丨</text><text
				style="font-weight: 700; font-size: 30rpx;">报事详情</text>
		</view>
		<view class="card" style="padding: 0 42rpx;">
			<u-form :model="form" ref="uForm">
				<u-form-item label="标题:">
					<u-input v-model="form.Reporter"
						placeholder-style="color: #000; text-align: right; font-weight: 600;" :placeholder="particulars.describe"
						:clearable="false" :disabled="true" />
				</u-form-item>
				<u-form-item label="类型:">
					<u-input v-model="form.address"
						placeholder-style="color: #000; text-align: right; font-weight: 600;" placeholder="建议"
						:clearable="false" :disabled="true" />
				</u-form-item>
				<u-form-item label="报事时间:">
					<u-input v-model="form.address"
						placeholder-style="color: #000; text-align: right; font-weight: 600;"
						placeholder="2021-06-09 12: 23: 32" :clearable="false" :disabled="true" />
				</u-form-item>
				<u-form-item label="事件地址:">
					<u-input v-model="form.address"
						placeholder-style="color: #000; text-align: right; font-weight: 600;" :placeholder="particulars.addressCommunity"
						:clearable="false" :disabled="true" />
				</u-form-item>
				<u-form-item label="事件描述:" label-position="top">
					<u-input v-model="form.describe" type="textarea"
						placeholder-style="color: #000; text-align: right; font-weight: 600;"
						:placeholder="particulars.describe" :clearable="false" :disabled="true" />
				</u-form-item>
<!-- 				<u-form-item>
					<view style="display: flex; justify-content: space-around;">
						<view style="width:210rpx; height: 316rpx; background-color: #f2f2f2;">
						</view>
						<view style="width:210rpx; height: 316rpx; background-color: #f2f2f2;">
						</view>
						<view style="width:210rpx; height: 316rpx; background-color: #f2f2f2;">
						</view>
					</view>
				</u-form-item> -->
				
				<u-form-item v-show="imagesVos.length!=0">
					<view style="display: flex; flex-wrap: wrap;">
						<view style="width:210rpx; height: 316rpx;margin-right: 10rpx;margin-bottom: 10rpx; background-color: #f2f2f2;" v-for="(item,index) in imagesVos">
							<image :src="item.imgUrl" mode="" style="width: 100%;height: 100%;"></image>
						</view>
					</view>
				</u-form-item>
				
				
			</u-form>
		</view>
		<!-- 工单分配 -->
		<view class="order_Allocation">
			<view class="data_Statistics" style="padding: 28rpx 24rpx 0 ;">
				<text style="font-weight: 700; font-size: 30rpx; color: #c4c4c4;">丨</text><text
					style="font-weight: 700; font-size: 30rpx;" v-if="transfer==1">工单分配</text>
				<text style="font-weight: 700; font-size: 30rpx;" v-if="transfer==2">工单分配1</text>
			</view>
			<view class="card" style="position: relative; padding: 0 42rpx;">
				<u-form :model="form" ref="uForm">
					<u-form-item label="选择负责人:">
						<u-input v-model="form.Reporter"
							placeholder-style="color: #000; text-align: right; font-weight: 600;" placeholder="刘备"
							:clearable="false" :disabled="true" />
					</u-form-item>
					<u-form-item label="选择执行人:">
						<u-input v-model="form.address"
							placeholder-style="color: #000; text-align: right; font-weight: 600;" :placeholder="particulars.staffName"
							:clearable="false" :disabled="true" />
					</u-form-item>
<!-- 					<u-form-item label="维保时间:">
						<u-input v-model="form.address"
							placeholder-style="color: #000; text-align: right; font-weight: 600;"
							placeholder="2021-06-09 12: 23: 32" :clearable="false" :disabled="true" />
					</u-form-item>
					<u-form-item label="结束时间:">
						<u-input v-model="form.address"
							placeholder-style="color: #000; text-align: right; font-weight: 600;"
							placeholder="2021-06-09 24: 23: 32" :clearable="false" :disabled="true" />
					</u-form-item> -->
					<u-form-item label="执行状态:" v-if="current==1&&transfer==1">
						<u-input v-model="form.address"
							placeholder-style="color: #000; text-align: right; font-weight: 600;" placeholder="待接单"
							:clearable="false" :disabled="true" />
					</u-form-item>
					<u-form-item label="执行状态:" v-if="current==2&&show==false">
						<u-input v-model="form.address"
							placeholder-style="color: #000; text-align: right; font-weight: 600;" placeholder="待接单"
							:clearable="false" :disabled="true" v-if="particulars.executeStatus==0" />
							<u-input v-model="form.address"
								placeholder-style="color: #000; text-align: right; font-weight: 600;" placeholder="完成"
								:clearable="false" :disabled="true" v-if="particulars.executeStatus==1" />
								<u-input v-model="form.address"
									placeholder-style="color: #000; text-align: right; font-weight: 600;" placeholder="未完成"
									:clearable="false" :disabled="true" v-if="particulars.executeStatus==2" />
									<u-input v-model="form.address"
										placeholder-style="color: #000; text-align: right; font-weight: 600;" placeholder="待执行"
										:clearable="false" :disabled="true" v-if="particulars.executeStatus==3" />
					</u-form-item>
					<u-form-item label="执行状态:" v-if="show==true&&btn!=2">
						<u-input v-model="form.address"
							placeholder-style="color: #000; text-align: right; font-weight: 600;" placeholder="执行中"
							:clearable="false" :disabled="true" />
					</u-form-item>
					<u-form-item label="执行状态:" v-if="btn==2&&transfer==1">
						<u-input v-model="form.address"
							placeholder-style="color: #000; text-align: right; font-weight: 600;" placeholder="已完成"
							:clearable="false" :disabled="true" />
					</u-form-item>
					<!-- 待转交 -->
					<u-form-item label="执行状态:" v-if="transfer==2">
						<u-input v-model="form.address"
							placeholder-style="color: #000; text-align: right; font-weight: 600;" placeholder="待转交"
							:clearable="false" :disabled="true" />
					</u-form-item>
					<image src="/static/workOrder/Group689.png" mode=""
						style=" position: absolute;top: 10rpx; left: 236rpx; width: 280rpx; height: 280rpx;"
						v-if="current==1&&transfer==1">
					</image>
					<!-- 待执行 -->
					<image src="/static/workOrder/Group801.png" mode=""
						style=" position: absolute;top: 10rpx; left: 236rpx; width: 280rpx; height: 280rpx;"
						v-if="current==2&&pop==false&&to==false">
					</image>
					<image src="/static/workOrder/Group690.png" mode=""
						style=" position: absolute;top: 10rpx; left: 236rpx; width: 280rpx; height: 280rpx;"
						v-if="pop==true">
					</image>
					<!-- 待复查 -->
					<image src="/static/workOrder/Group803.png" mode=""
						style=" position: absolute;top: 10rpx; left: 236rpx; width: 280rpx; height: 280rpx;"
						v-if="btn==2&&transfer==1">
					</image>
					<!-- 待转交 -->
					<image src="/static/workOrder/Group690.png" mode=""
						style=" position: absolute;top: 10rpx; left: 236rpx; width: 280rpx; height: 280rpx;"
						v-if="transfer==2">
					</image>
				</u-form>
			</view>
		</view>
		<!-- 执行信息 -->
		<view class="data_Statistics" style="padding: 44rpx 24rpx 0 ;" v-if="show==true">
			<text style="font-weight: 700; font-size: 30rpx; color: #c4c4c4;">丨</text><text
				style="font-weight: 700; font-size: 30rpx;">执行信息</text>
		</view>
		<!-- 正常新建工单 -->
		<view class="card" v-if="show==true">
			<uni-card class="second_card" style="margin: 0;">
				<u-form :model="form" ref="uForm">
					<u-form-item label="事件描述:" label-position="top">
						<u-input v-model="form.end" type="textarea"
							placeholder-style="color: #cccccc; text-align: left;" placeholder="请输入执行过程"
							:disabled="disabled" />
					</u-form-item>
				<!-- 	<u-upload :action="action" :custom-btn="true">
						<view slot="addBtn" class="slot-btn" hover-class="slot-btn__hover" hover-stay-time="150">
							<u-icon name="plus" size="60" :color="$u.color['lightColor']"></u-icon>
							<view class="add_Photo">点击添加图片</view>
						</view>
					</u-upload> -->
					
					<u-upload :action="$http.host()+'uploadAvatar'" :custom-btn="true" @on-change='change_status'>
						<view slot="addBtn" class="slot-btn" hover-class="slot-btn__hover" hover-stay-time="150">
							<u-icon name="plus" size="60" :color="$u.color['lightColor']"></u-icon>
							<view class="add_Photo">点击添加图片</view>
						</view>
					</u-upload>
					
				</u-form>
			</uni-card>
		</view>
		<view class="button" v-if="transfer==1">
			<!-- 待接单按钮 -->
			<u-button type="primary" style="flex: 1;" @click="resolved" v-if="current==1">接单</u-button>
			<u-button type="success" style="flex: 1;" @click="Approved" v-if="current==1">转交</u-button>
			<!-- 待执行按钮 -->
			<u-button type="success" style="flex: 1;" @click="implement" v-if="current==2&&show==false">执行</u-button>
			<u-button type="success" style="flex: 1;" @click="submit" v-if="show==true&&btn!=2">提交</u-button>
		</view>
		<view class="button" v-if="transfer==2">
			<u-button type="primary" style="flex: 1;" @click="cancel">取消</u-button>
			<u-button type="success" style="flex: 1;" @click="determine">确定</u-button>
		</view>
		<u-popup v-model="pop" mode="center" width="626rpx" height="430rpx" border-radius="20" @close="close">
			<view
				style="height: 54rpx; line-height: 54rpx; font-weight: 600; color: #a1a1a1; background-color: #fbfbfb; text-align: center;">
				工单完成提交</view>
			<view class="work_Order">
				<view class="work_Order_top"></view>
				<view class="work_Order_bottom" style="margin-top: 10rpx;">提交完成！</view>
			</view>
		</u-popup>
		<!-- 工单转交弹框 -->
		<u-popup v-model="transfer_pop" mode="center" width="626rpx" height="430rpx" border-radius="20" @close="close">
			<view
				style="height: 54rpx; line-height: 54rpx; font-weight: 600; color: #a1a1a1; background-color: #fbfbfb; text-align: center;">
				工单转交</view>
			<view class="work_Order">
				<view class="work_Order_top"></view>
				<view class="work_Order_bottom" style="margin-top: 10rpx;">转交完成！</view>
			</view>
		</u-popup>
		<!-- 弹框 -->
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// form表单
				form: {
					Reporter: '',
					title: '',
					address: '',
					describe: '',
					chargePerson: '',
					Executor: '',
					Maintenance: '',
					end: ''
				},
				// 演示地址，请勿直接使用
				// 预置图片
				// fileList: [{
				// 	url: 'http://pics.sc.chinaz.com/files/pic/pic9/201912/hpic1886.jpg',
				// }],
				button_flag: true,
				buttontwo_flag: false,
				current: 2,
				// 控制点击执行后显示的内容
				show: false,
				// 控制弹框是否弹出
				pop: false,
				// 控制转交工单弹框
				transfer_pop:false,
				// 控制待复查图片和按钮
				btn: 1,
				// 是否禁用输入框
				disabled: false,
				// 点击转交触发
				transfer: 1,
				// 控制待执行图片
				to:false,
				// 报事报修待执行Id
				orderId:'',
				// 车辆详情
				particulars:'',
								imagesVos:'',
				// 审核通过
				staff:'',
				count: 1,
				value: 0,
				userPhone: '',
				userName: '',
				// 图片保存
				img_List:[],
				// str:''
			}
		},
		onLoad(val) {
			console.log(val)
			this.loginId = uni.getStorageSync("setModel")
			if(val.orderId){
			this.orderId=val.orderId
				// 报事报修待执行详情
				this.getListVehicleByIds()
			}
			// this.loading()
		},
		methods: {
			change_status(res) {
				// console.log(res)
				// console.log(res.data.data,'----------')
				// let img = JSON.parse(res.data)
				// console.log(img.data,'----------')
				// console.log(JSON.parse(res.data),'----------')
				// let img = JSON.parse(res.data.data)
				if (res.statusCode == 200) {
					let img = JSON.parse(res.data)
					let img_two=img.data
					this.img_List.push(img_two)
					console.log(this.img_List)
					// this.str=this.img_List.join(',')
					// console.log(JSON.parse(this.img_List))
				}
			},
			// 收藏电话号码
			change(e) {
				console.log(e)
				this.$http.post('Collect/insertOwnerTenant', {
					userPhone: this.userPhone,
					userId: this.loginId.userId,
					userName: this.userName
				}).then(res => {
					console.log(res, '收藏电话号码')
					// this.particulars=res.data
				})
			},
			// 报事报修待执行详情
			getListVehicleByIds() {
				this.$http.get('WorkOrder/getToBeExecutedById',{orderId:this.orderId,loginId:this.loginId.userId}).then(res => {
					this.particulars=res.data
					this.imagesVos=res.data.imagesVos
					this.userPhone = res.data.phoneNumber
					this.userName = res.data.reportPerson
					console.log(res, '报事报修待执行详情')
					// this.owners = res.data
				})
			},
			// 接单
			resolved() {
				this.current = 2
				// uni.navigateBack()
			},
			// 转交
			Approved() {
				this.transfer = 2
			},
			// 执行
			implement() {
				this.show = true
			},
			// 提交
			submit() {
				if (this.form.end != '') {
					// this.pop = true
					this.disabled = true
					// 点击提交
					this.$http.put('WorkOrder/updateReportOrderExecuted',{
						orderId:this.orderId,
						executeMethod:this.form.end,
						images:this.img_List,
						staffName:this.loginId.staffName
						}).then(res => {
							if(res.code==500) {
								this.$refs.uToast.show({
									title: res.msg,
								})
								
								console.log(res, '报事报修点击接单')
								setTimeout(function() {
									uni.navigateBack()
								}, 1000);
							} else {
								uni.navigateBack()
								// that.pop = true
								// this.to=true
							}
						// this.particulars=res.data
						console.log(res, '点击提交')
						// that.pop = true
						// this.owners = res.data
						// setTimeout(function() {
						// 	uni.navigateBack()
						// }, 1000);
					})
				}
				// if(this.pop=false) {
				// 	this.btn=2
				// }
			},
			// 取消
			cancel() {
				this.transfer=1
				this.btn=1
			},
			// 确定
			determine(){
				this.transfer_pop=true
			},
			// 弹出层收起
			close() {
				this.btn = 2
			}
			// determine() {
			// 	this.show = true
			// 	console.log(171)
			// 	setTimeout(function() {
			// 		uni.navigateBack()
			// 	}, 1000);
			// }
		}
	}
</script>

<style lang="scss" scoped>
	.newworkOrder_container {
		.mail_List {
			overflow: hidden;
			width: 100%;
			background-color: #f2f2f2;

			.mail {
				padding: 10rpx 0;
				// margin-top: 96rpx;
				color: #999999;
				font-size: 40rpx;
				background-color: #e5e5e5;
			}

			.order {
				text-align: center;
			}
		}

		/deep/.card {
			.u-form-item--left {
				flex: unset !important;
				width: unset !important;
			}

			.second_card {
				.u-form-item {
					padding: 0;
				}

				.uni-card__content {
					padding: 0 24rpx;
				}
				
				
				/deep/.u-list-item {
					margin: 9rpx !important;
				}
			}
		}

		.icon {
			position: absolute;
			top: 18rpx;
			// top: 114rpx;
			left: 20rpx;
		}

		.second_card {
			.u-cell {
				padding: 18rpx 32rpx;

				/deep/.u-cell__value {
					color: #333333;
					font-weight: 600;
				}
			}

			/deep/.uni-card__content {
				padding: 16rpx 24rpx;
			}

			/deep/.u-input__input {
				min-height: 60rpx !important;
			}
			/deep/.u-list-item {
				margin: 9rpx !important;
			}
		}

		/deep/button {
			border-radius: unset !important;
		}

		.uni-border[data-v-19622063]:after {
			border: unset;
		}

		/deep/.uni-border.data-v-19622063:after {
			border: unset;
		}

		.slot-btn {
			display: flex;
			flex-direction: column;
			width: 200rpx;
			height: 200rpx;
			display: flex;
			justify-content: center;
			margin: 10rpx;
			// margin-top: 20rpx;
			align-items: center;
			background-color: #e5e5e5;

			.add_Photo {
				margin-top: 10rpx;
				color: #cccccc;
			}
		}

		.slot-btn__hover {
			background-color: rgb(235, 236, 238);
		}


		.button {
			display: flex;
			// position: fixed;
			// left: 0;
			// right: 0;
			// bottom: 0;
			margin-top: 200rpx;
			border-radius: 14rpx;
			overflow: hidden;
			z-index: 9;

			.u-btn {
				border-radius: unset;
			}
		}

		.work_Order {
			margin-top: 60rpx;
			text-align: center;

			.work_Order_top {
				width: 168rpx;
				height: 168rpx;
				margin: 0 auto;
				background-color: #e5e5e5;
				border-radius: 50%;
			}
		}
	}
</style>
